import Vue from 'vue'
import Cookies from 'js-cookie' // 操作cookie
import 'normalize.css/normalize.css' // 重置css  a modern alternative to CSS resets
import Element from 'element-ui' //
// 引入常量
import CONSTANT from '@/utils/constant'
// 引入本地存储
import {setJsonObjectToLocal,getJsonObjectFromLocal,clearDataFromLocal} from '@/utils/localstorage'
import { getToken, setToken, removeToken,getOutboundToken,setOutboundToken,removeOutboundToken } from '@/utils/auth'
import './styles/element-variables.scss' // 主题css
// import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖
import '@/styles/index.scss' // 全局css global css
import App from './App'
import store from './store' // vuex
import router from './router' // vue-router
import Moment from 'moment' // moment
//接口文件
import api from './api/index.js'
//引入echarts
import * as echarts from 'echarts'

//vue全局注入echarts
Vue.prototype.$echarts = echarts;

Vue.prototype.setJsonObjectToLocal = setJsonObjectToLocal
// 把常量引入到全局变量中
Vue.prototype.$CONSTANT = CONSTANT
Vue.prototype.getToken = getToken
Vue.prototype.setToken = setToken
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
import Pagination from '@/components/Pagination' // pagination 分页
import * as filters from './filters' // 全局过滤器 global filters
import 'babel-polyfill' // ie兼容
import BcElement from '@/directive/bc-element/index' // 元素权限控制

Vue.prototype.$api = api;
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import '@/utils/detectZoom'
Vue.use(VXETable)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// 全局组件挂载 register global utility components
Vue.component('Pagination', Pagination)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size 设置element-ui默认尺寸
})

// 注册全局过滤器 register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
Vue.prototype.$bus = new Vue();
// 绑定属性
Vue.prototype.moment = Moment
// 安装全局组件或指令， 需要有install函数
Vue.use(BcElement)
window.Promise = Promise
//store.dispatch('user/getUrl'); // url
import $ from 'jquery'
Vue.prototype.$ = $

router.beforeEach((to, from, next) => {
  let adminToken = getToken();
  if (to.meta.title) {
    // 这里设置header部分的title
    document.title =  to.meta.title
  }
  if (to.meta.login) {
    if (!adminToken) {
      next({
        path: '/login'
      })
      return
    }
  }
  next()
})

var globalVue = new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
window.vue = globalVue

